package net.borlis.sample.services.facade.ws.response.util;

import net.borlis.dictionaries.product.HierarchyLevelDictionary;
import net.borlis.dictionaries.product.LifecycleStateDictionary;
import net.borlis.sample.service.entities.common.ChangeType;
import net.borlis.sample.service.entities.configuration.interfaces.ICreditCardDetailEntity;
import net.borlis.sample.service.entities.configuration.interfaces.ITravelPeriodEntity;
import net.borlis.sample.service.entities.configuration.parents.VitoEntity;
import net.borlis.sample.service.entities.general.*;
import net.borlis.sample.service.entities.history.*;
import net.borlis.sample.service.entities.lifecycle.Lifecycle;
import net.borlis.sample.service.entities.lifecycle.LifecycleAction;
import net.borlis.sample.services.facade.ws.request.HistoryFilterView;
import net.borlis.sample.services.facade.ws.request.TravelDurationRequest;
import net.borlis.sample.services.facade.ws.response.*;
import net.borlis.sample.services.output.*;
import net.borlis.scheduler.lifecycle.UploadStatus;
import org.apache.commons.lang.StringUtils;

import javax.enterprise.context.RequestScoped;
import java.util.*;

import static com.google.common.base.Charsets.UTF_8;

/**
 * The translator between data entities and UI view beans.
 *
 * @author alex@borlis.net
 */
@RequestScoped
public class BuilderViewData implements IBuilderViewData {

    private static final String NOT_TRANSLATED = "NOT TRANSLATED";

    /**
     * {@inheritDoc}
     */
    @Override
    public DynamixLocaleResponse createDynamixLocaleViewData(DynamixLocaleEntity locale) {
        return new DynamixLocaleResponse(locale.getId(), locale.getCode(), locale.getName());
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public ProviderResponse createProviderViewData(DynamixProviderDetailEntity providerDetail) {
        return new ProviderResponse(providerDetail.getId(), providerDetail.getDynamixProvider().getCode(), providerDetail.getLabel());
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public CountryResponse createCountryViewData(CountryDetailEntity countryDetail, CurrencyDetailEntity currencyDetail) {
        return new CountryResponse(countryDetail.getCountry().getId(),
                countryDetail.getCountry().getCode(), countryDetail.getName(),
                createCurrencyViewData(currencyDetail));
    }

    private CurrencyResponse createCurrencyViewData(CurrencyDetailEntity currencyDetail) {
        return new CurrencyResponse(currencyDetail.getCurrency().getId(),
                currencyDetail.getCurrency().getCode(), currencyDetail.getLabel());
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public VitoResponse createVitoViewData(VitoFilteredLocalized vitoLocalized) {
        return new VitoResponse(
                vitoLocalized.getVito().getId(),
                vitoLocalized.getVito().getCode(),
                vitoLocalized.getVito().getName(),
                vitoLocalized.getVito().getMainOrganisation().getKidShortname(),
                getNumberOfEnabledProviders(vitoLocalized.getHotelProviders()),
                getNumberOfEnabledProviders(vitoLocalized.getFlightProviders()),
                createCountryViewData(vitoLocalized.getCountry(), vitoLocalized.getCurrency()));
    }

    private List<ProviderWithVitoResponse> createProviderWithVitoViewDataList(List<ProviderConfigured> providersConfigured) {
        List<ProviderWithVitoResponse> result = new ArrayList<ProviderWithVitoResponse>();
        for (ProviderConfigured providers : providersConfigured) {
            result.add(createProviderWithVitoViewData(providers));
        }
        return result;
    }

    private Integer getNumberOfEnabledProviders(List<ProviderConfigured> providers) {
        Integer result = 0;
        for (ProviderConfigured provider : providers) {
            if (provider.getEnabled()) {
                result++;
            }
        }
        return result;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public VitoWithProvidersResponse createVitoWithProvidersViewData(VitoFilteredLocalized vitoLocalized) {

        List<ProviderConfigured> configuredHotelsProviders = vitoLocalized.getHotelProviders();
        List<ProviderConfigured> configuredFlightsProviders = vitoLocalized.getFlightProviders();

        return new VitoWithProvidersResponse(
                vitoLocalized.getVito().getId(),
                vitoLocalized.getVito().getCode(),
                vitoLocalized.getVito().getName(),
                vitoLocalized.getVito().getMainOrganisation().getKidShortname(),
                createCountryViewData(vitoLocalized.getCountry(), vitoLocalized.getCurrency()),
                createProviderWithVitoViewDataList(configuredHotelsProviders),
                createProviderWithVitoViewDataList(configuredFlightsProviders),
                getNumberOfEnabledProviders(configuredHotelsProviders),
                getNumberOfEnabledProviders(configuredFlightsProviders));
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public ProviderResponse createProviderViewData(ProviderLocalized providerLocalized) {
        return new ProviderResponse(providerLocalized.getTypedDynamixProvider().getId(),
                providerLocalized.getTypedDynamixProvider().getDynamixProvider().getCode(),
                providerLocalized.getDynamixProviderDetail().getLabel());
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Map<LifecycleStateDictionary, GetLifecycleStateResponse> createLifeCycleConfigurationsViewData(List<Lifecycle> lifecycleList) {
        Map<LifecycleStateDictionary, GetLifecycleStateResponse> result = new HashMap<LifecycleStateDictionary, GetLifecycleStateResponse>();
        for (Lifecycle lifecycle : lifecycleList) {
            GetLifecycleStateResponse resultValue = new GetLifecycleStateResponse();
            List<LifecycleEventResponse> responses = new ArrayList<LifecycleEventResponse>();
            List<LifecycleAction> actions = new ArrayList<LifecycleAction>();
            if (!lifecycle.getActionSet().isEmpty()) {
                actions.addAll(lifecycle.getActionSet());
            }
            for (LifecycleAction action : actions) {
                responses.add(new LifecycleEventResponse(action.getActionType(), action.getChangedOn().getTime(),
                        action.getUserLogin()));
            }
            resultValue.setEvents(responses);
            resultValue.setProcessing(lifecycle.getLocked());
            result.put(lifecycle.getStateStatus().getState().getState(), resultValue);
        }
        return result;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public ProviderWithVitoResponse createProviderWithVitoViewData(ProviderConfigured providerConfigured) {
        return new ProviderWithVitoResponse(providerConfigured.getTypedDynamixProvider().getId(),
                providerConfigured.getTypedDynamixProvider().getDynamixProvider().getCode(),
                providerConfigured.getDynamixProviderDetail().getLabel(),
                providerConfigured.getEnabled(), providerConfigured.getSaleType());
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public VitoFilterResponse createVitoFilterViewData(FilterLocalized filterLocalized) {
        return new VitoFilterResponse(
                createBaseCountryViewDataList(filterLocalized.getCountries()),
                createBaseVitoViewDataList(filterLocalized.getVitoList()),
                createProviderViewDataList(filterLocalized.getHotelProviders()),
                createProviderViewDataList(filterLocalized.getFlightProviders())
        );
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List<BaseVitoResponse> createBaseVitoViewDataList(List<VitoEntity> vitoList) {
        List<BaseVitoResponse> result = new ArrayList<BaseVitoResponse>();
        for (VitoEntity vito : vitoList) {
            result.add(new BaseVitoResponse(vito.getId(), vito.getCode(), vito.getName()));
        }
        return result;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public UploadStatusResponse createUploadStatusViewData(UploadStatus us) {
        return new UploadStatusResponse(us.getUploadDate(), us.getUploadStatus());
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public TravelPeriodResponse createTravelPeriodViewData(TravelPeriodLocalized tp) {
        TravelPeriodResponse tpr = new TravelPeriodResponse();
        tpr.setId(tp.getTravelPeriod().getId());
        tpr.setName(tp.getTravelPeriod().getName());
        tpr.setStartDate(tp.getTravelPeriod().getStartDate().getTime());
        return tpr;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public GetHistoryResponseContainer buildHistorySearchResponse(HistoryViewResultResponse mwResult) {
        GetHistoryResponseContainer container = new GetHistoryResponseContainer();
        container.setItemsCount(mwResult.getItemsCount());
        List<HistoryViewResult> historyViewResultList = mwResult.getHistoryViewResultList();
        List<GetHistoryResponse> items = new ArrayList<GetHistoryResponse>();
        for (HistoryViewResult hvr : historyViewResultList) {
            GetHistoryResponse item = new GetHistoryResponse();
            item.setResultType(hvr.getManuLabel());
            item.setUser(hvr.getDynamixAccountId().toString());
            if (hvr.getUploadTime() != null) {
                item.setUploadedAt(hvr.getUploadTime().getTime());
            }
            item.setChangeTime(hvr.getChangeTime().getTime());
            item.setAfter(hvr.getAfter());
            item.setBefore(hvr.getBefore());
            item.setChangeCategory(hvr.getChangeType().type());
            item.setElement(hvr.getElementName());
            item.setElementType(hvr.getElementType());
            items.add(item);
        }
        container.setItems(items);
        return container;
    }

    @Override
    public List<IdLabelResponse> buildMenuItemsResponse(Collection<DpctMenu> menuItems, String localeCode) {
        List<IdLabelResponse> resultList = new ArrayList<IdLabelResponse>();
        for (DpctMenu dpctMenu : menuItems) {
            IdLabelResponse idLabelResponse = new IdLabelResponse();
            idLabelResponse.setId(dpctMenu.getId());
            idLabelResponse.setLabel(NOT_TRANSLATED);
            Set<DpctMenuDetail> dpctMenuDetails = dpctMenu.getDpctMenuDetails();
            for (DpctMenuDetail dpctMenuDetail : dpctMenuDetails) {
                if (dpctMenuDetail.getDynamixLocaleEntity().getCode().equals(localeCode)) {
                    idLabelResponse.setLabel(dpctMenuDetail.getLabel());
                }
            }
            resultList.add(idLabelResponse);
        }
        return resultList;
    }

    @Override
    public HistoryFilterView buildViewFilterForLifecycleConfiguration(HistoryFilter filter) {
        List<String> changeTypeStrList = new ArrayList<String>();
        List<ChangeType> changeTypes = filter.getChangeCategoryList();
        for (ChangeType ct : changeTypes) {
            changeTypeStrList.add(ct.name());
        }
        HistoryFilterView result = new HistoryFilterView(
                filter.getChangeFrom().getTime(),
                filter.getChangeTo().getTime(),
                changeTypeStrList.toArray(new String[changeTypeStrList.size()]));
        return result;
    }

    @Override
    public List<IdLabelResponse> buildActionTypes(List<HistoryActionType> actionTypes) {
        List<IdLabelResponse> resultList = new ArrayList<IdLabelResponse>();
        for (HistoryActionType hat : actionTypes) {
            IdLabelResponse idLabelResponse = new IdLabelResponse();
            idLabelResponse.setId(hat.getId());
            idLabelResponse.setLabel(NOT_TRANSLATED);
            resultList.add(idLabelResponse);
        }
        return resultList;
    }

    @Override
    public List<IdLabelResponse> createElementTypes(List<HistoryElementType> elementTypes, String locale) {
        List<IdLabelResponse> resultList = new ArrayList<IdLabelResponse>();
        for (HistoryElementType het : elementTypes) {
            IdLabelResponse idLabelResponse = new IdLabelResponse();
            idLabelResponse.setId(het.getId());
            idLabelResponse.setLabel(NOT_TRANSLATED);
            Set<HistoryElementTypeDetail> historyElementTypeDetailSet = het.getHistoryElementTypeDetailSet();
            for (HistoryElementTypeDetail hetd : historyElementTypeDetailSet) {
                if (hetd.getDynamixLocale().getCode().equals(locale)) {
                    idLabelResponse.setLabel(hetd.getLabel());
                }
            }
            resultList.add(idLabelResponse);
        }
        return resultList;
    }

    @Override
    public Set<IdLabelResponse> createResultTypes(List<HistoryElement> elements, String locale) {
        Set<IdLabelResponse> resultList = new HashSet<>();
        for (HistoryElement he : elements) {
            IdLabelResponse idLabelResponse = new IdLabelResponse();
            idLabelResponse.setId(he.getId());
            idLabelResponse.setLabel(NOT_TRANSLATED);
            Set<HistoryElementDetail> historyElementDetailSet = he.getHistoryElementDetailSet();
            for (HistoryElementDetail hed : historyElementDetailSet) {
                if (hed.getDynamixLocale().getCode().equals(locale)) {
                    idLabelResponse.setLabel(hed.getLabel());
                }
            }
            resultList.add(idLabelResponse);
        }
        return resultList;
    }

    private List<ProviderResponse> createProviderViewDataList(List<ProviderLocalized> providers) {
        List<ProviderResponse> result = new ArrayList<ProviderResponse>();
        for (ProviderLocalized provider : providers) {
            result.add(createProviderViewData(provider));
        }
        return result;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List<BaseCountryResponse> createBaseCountryViewDataList(List<CountryDetailEntity> countryDetails) {
        List<BaseCountryResponse> result = new ArrayList<BaseCountryResponse>();
        for (CountryDetailEntity detail : countryDetails) {
            result.add(createBaseCountryViewData(detail));
        }
        return result;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public BaseCountryResponse createBaseCountryViewData(CountryDetailEntity countryDetail) {
        return new BaseCountryResponse(countryDetail.getCountry().getId(), countryDetail.getCountry().getCode(), countryDetail.getName());
    }


    /**
     * {@inheritDoc}
     */
    @Override
    public HistoryFilter createHistoryFilterByRequest(HistoryFilterView request, Long vitoId, Long userId,
                                                      String locale) {
        List<ChangeType> changeTypes = new ArrayList<ChangeType>();
        if (request.getChangeCategories().length != 0) {
            for (String ct : request.getChangeCategories()) {
                changeTypes.add(ChangeType.valueOf(ct));
            }
        } else {
            changeTypes.add(ChangeType.I);
            changeTypes.add(ChangeType.U);
            changeTypes.add(ChangeType.D);
        }
        Date changeFrom = null;
        Date changeTo = null;
        Date uploadFrom = null;
        Date uploadTo = null;
        if (request.getChangeFrom() != null) {
            changeFrom = new Date(request.getChangeFrom());
        }
        if (request.getChangeTo() != null) {
            changeTo = new Date(request.getChangeTo());
        }
        if (request.getUploadFrom() != null) {
            uploadFrom = new Date(request.getUploadFrom());
        }
        if (request.getUploadTo() != null) {
            uploadTo = new Date(request.getUploadTo());
        }
        SortOrder sortOrder = null;
        HistorySortKey historySortKey = null;
        if (!StringUtils.isEmpty(request.getSortO()) && !StringUtils.isEmpty(request.getSortK())) {
            sortOrder = SortOrder.valueOf(request.getSortO());
            historySortKey = HistorySortKey.valueOf(request.getSortK());
        } else {
            sortOrder = SortOrder.A;
            historySortKey = HistorySortKey.changeTime;
        }
        HistoryFilter filter = new HistoryFilter(changeTypes, changeFrom, changeTo, uploadFrom, uploadTo,
                request.getFrom(), request.getItems(), request.getActionType(), request.getElement(),
                request.getElementType(), userId, request.getUser(), locale, vitoId, sortOrder, historySortKey,
                request.getResultType() != null ? request.getResultType() : null);
        return filter;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public GetHistoryResponseContainer createHistoryResponse(HistoryResultFiltered history) {
        List<GetHistoryResponse> responseList = new ArrayList<GetHistoryResponse>();
        GetHistoryResponseContainer container = new GetHistoryResponseContainer();
        if (!history.getHistory().isEmpty()) {
            container.setItemsCount(history.getItemsCount());
        } else {
            container.setItemsCount(0);
        }
        for (HistoryResult hr : history.getHistory()) {
            GetHistoryResponse ghr = new GetHistoryResponse();

            ghr.setActionType(hr.getDpctMenu().getDescription());

            //todo:: remove after translations
            ghr.setElementType(NOT_TRANSLATED);
            Set<HistoryElementTypeDetail> hetds = hr.getElementType().getHistoryElementTypeDetailSet();
            for (HistoryElementTypeDetail hetd : hetds) {
                if (hetd.getDynamixLocale().equals(history.getLocale())) {
                    ghr.setElementType(hetd.getLabel());
                }
            }

            //todo:: remove after translations
            ghr.setElement(NOT_TRANSLATED);
            ghr.setResultType(NOT_TRANSLATED);
            if (hr.getLabel() != null) {
                ghr.setResultType(hr.getLabel());
            }

            ghr.setElement(hr.getLabel());
            Set<HistoryElementDetail> heds = hr.getElement().getHistoryElementDetailSet();
            for (HistoryElementDetail hed : heds) {
                if (hed.getDynamixLocale().equals(history.getLocale())) {
                    ghr.setElement(hed.getLabel());
                    //todo:: find out which result type to set
//                    ghr.setResultType(hed.getLabel());
                }
            }
            ghr.setChangeCategory(hr.getChangeCategory().type());
            ghr.setBefore(hr.getBefore());
            ghr.setAfter(hr.getAfter());
            ghr.setChangeTime(hr.getChangeTime().getTime());
            if (hr.getUploadAt() != null) {
                ghr.setUploadedAt(hr.getUploadAt().getTime());
            }
            ghr.setUser(hr.getUserChangedName());
            responseList.add(ghr);
        }
        container.setItems(responseList);
        return container;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public FilterGetResultTypeResponse createGetResultTypeResponse(List<HistoryElement> elements, String localeCode) {
        List<IdLabelResponse> viewBeans = new ArrayList<IdLabelResponse>();
        for (HistoryElement he : elements) {
            IdLabelResponse idLabelResponse = new IdLabelResponse();
            idLabelResponse.setId(he.getId());
            idLabelResponse.setLabel(NOT_TRANSLATED);
            Set<HistoryElementDetail> heds = he.getHistoryElementDetailSet();
            for (HistoryElementDetail hed : heds) {
                if (hed.getDynamixLocale().getCode().equals(localeCode)) {
                    idLabelResponse.setLabel(hed.getLabel());
                }
            }
            viewBeans.add(idLabelResponse);
        }
        FilterGetResultTypeResponse response = new FilterGetResultTypeResponse();
        response.setResultType(viewBeans);
        return response;
    }

    @Override
    public List<TravelDurationEntity> createTravelDurations(List<TravelDurationRequest> travelDurationBeanList) {
        List<TravelDurationEntity> resultList = new ArrayList<>();
        for (TravelDurationRequest bean : travelDurationBeanList) {
            TravelDurationEntity entity = new TravelDurationEntity(bean.getFrom(), bean.getTo());
            resultList.add(entity);
        }
        return resultList;
    }

    @Override
    public List<TravelPeriodResponse> createTravelPeriodViewData(List<ITravelPeriodEntity> travelPeriods) {
        List<TravelPeriodResponse> resultList = new ArrayList<>();
        for (ITravelPeriodEntity entity : travelPeriods) {
            TravelPeriodResponse response = new TravelPeriodResponse();
            response.setStartDate(entity.getStartDate().getTime());
            response.setId(entity.getId());
            response.setName(entity.getName());
            resultList.add(response);
        }
        return resultList;
    }

    @Override
    public VitoAddressResponse createVitoAddressViewData(VitoAddressLocalized va) {
        if (va == null) {
            return null;
        }
        VitoAddressResponse var = new VitoAddressResponse();
        var.setId(va.getVitoAddress().getId());
        var.setCity(va.getVitoAddress().getCity());
        var.setCountryCode(va.getVitoAddress().getCountry().getCode());
        var.setEmail(va.getVitoAddress().getEmail());
        var.setFax(va.getVitoAddress().getFax());
        var.setFirstName(va.getVitoAddress().getFirstName());
        var.setLastName(va.getVitoAddress().getLastName());
        var.setMobile(va.getVitoAddress().getMobile());
        var.setSalutation(va.getVitoAddress().getSalutation());
        var.setStreet(va.getVitoAddress().getStreet());
        var.setTelephone(va.getVitoAddress().getTelephone());
        var.setTitle(va.getVitoAddress().getTitle());
        var.setZipCode(va.getVitoAddress().getZipCode());
        return var;
    }

    @Override
    public List<VitoAddressResponse> createVitoAddressViewData(List<VitoAddressLocalized> vitoAddresses) {
        List<VitoAddressResponse> resultList = new ArrayList<>();
        for (VitoAddressLocalized va : vitoAddresses) {
            resultList.add(createVitoAddressViewData(va));
        }
        return resultList;
    }

    @Override
    public List<BankAccountResponse> createBankAccountViewData(List<BankDetailLocalized> bankDetails) {
        List<BankAccountResponse> resultList = new ArrayList<>();
        for (BankDetailLocalized ba : bankDetails) {
            resultList.add(createBankAccountViewData(ba));
        }
        return resultList;
    }

    @Override
    public BankAccountResponse createBankAccountViewData(BankDetailLocalized bd) {
        BankAccountResponse bar = new BankAccountResponse();
        bar.setId(bd.getBankDetail().getId());
        bar.setAccountHolderFirstName(bd.getBankDetail().getAccountHolderFirstName());
        bar.setAccountHolderLastName(bd.getBankDetail().getAccountHolderLastName());
        if (bd.getBankDetail().getAccountNumber() != null) {
            bar.setAccountNumber(new String(bd.getBankDetail().getAccountNumber(), UTF_8));
        }
        if (bd.getBankDetail().getBankCode() != null) {
            bar.setBankCode(bd.getBankDetail().getBankCode());
        }
        bar.setBank(bd.getBankDetail().getBankName());
        bar.setBic(new String(bd.getBankDetail().getBic(), UTF_8));
        bar.setIban(new String(bd.getBankDetail().getIban(), UTF_8));
        return bar;
    }

    @Override
    public CreditCardDetailResponse createCreditCardViewData(ICreditCardDetailEntity creditCard) {
        return new CreditCardDetailResponse(creditCard);
    }

    @Override
    public List<CreditCardDetailResponse> createCreditCardViewData(List<ICreditCardDetailEntity> creditCards) {
        List<CreditCardDetailResponse> resultList = new ArrayList<>();
        for (ICreditCardDetailEntity cc : creditCards) {
            resultList.add(createCreditCardViewData(cc));
        }
        return resultList;
    }

    @Override
    public CreditCardTypeResponse createCreditCardTypeViewData(CreditCardTypeEntity cct) {
        return new CreditCardTypeResponse(cct.getId(), cct.getCode(), cct.getName());
    }

    @Override
    public ProviderBookingInfoResponse createProviderBookingInfoViewData(ProviderBookingInfoLocalized info) {
        return new ProviderBookingInfoResponse(
                info.getId(),
                info.getProviderCode(),
                info.getAddressId(),
                info.getPaymentType(),
                info.getPaymentId(),
                info.getState(),
                info.getBc(),
                info.getBq(),
                info.getNx()
        );
    }

    @Override
    public List<ProviderBookingInfoResponse> createProviderBookingInfoViewData(List<ProviderBookingInfoLocalized> infoList) {
        List<ProviderBookingInfoResponse> resultList = new ArrayList<>();
        for (ProviderBookingInfoLocalized info : infoList) {
            resultList.add(createProviderBookingInfoViewData(info));
        }
        return resultList;
    }

    @Override
    public List<BookingConfigResponse> createBookingConfigViewData(List<BookingConfigLocalized> bookingConfigs) {
        List<BookingConfigResponse> resultList = new ArrayList<>();
        for (BookingConfigLocalized bc : bookingConfigs) {
            resultList.add(createBookingConfigViewData(bc));
        }
        return resultList;
    }

    @Override
    public BookingConfigResponse createBookingConfigViewData(BookingConfigLocalized bookingConfig) {
        return new BookingConfigResponse(
                bookingConfig.getId(),
                bookingConfig.getHotelProviderCode(),
                bookingConfig.getHotelProviderName(),
                bookingConfig.getFlightProviderCode(),
                bookingConfig.getFlightProviderName(),
                bookingConfig.getStrategyCode(),
                bookingConfig.getStrategyName()
        );
    }

    @Override
    public BookingConfigStrategyResponse createBookingConfigStrategyViewData(BookingConfigStrategyEntity bcs) {
        return new BookingConfigStrategyResponse(bcs.getId(), bcs.getCode(), bcs.getName());
    }

    @Override
    public PortfolioSettingResponse createPortfolioSettingViewData(PortfolioSettingLocalized ps) {
        return new PortfolioSettingResponse(
                createTravelPeriodViewData(ps.getTravelPeriod()),
                ps.getPackaging(),
                ps.getReleaseDays(),
                createTravelDurationsViewData(ps.getTravelDurations()),
                ps.getHierarchyLevel(),
                ps.getFirstFixedMargin(),
                ps.getSecondFixedMargin(),
                ps.getRelativeMargin()
        );
    }

    @Override
    public List<TravelDurationResponse> createTravelDurationsViewData(List<TravelDurationLocalized> travelDurations) {
        List<TravelDurationResponse> res = new ArrayList<>();
        for (TravelDurationLocalized td : travelDurations) {
            res.add(new TravelDurationResponse(td.getDurationFrom(), td.getDurationTo()));
        }
        return res;
    }

    @Override
    public HierarchyLevelResponse createHierarchyLevelViewData(HierarchyLevelDictionary hierarchyLevelEnumValue, String hierarchyLevelName) {
        return new HierarchyLevelResponse(
                hierarchyLevelEnumValue,
                hierarchyLevelName
        );
    }

}
